package club.zhcs.capture.vo;

import java.io.File;

import club.zhcs.capture.bean.auth.Permission;
import club.zhcs.capture.bean.auth.Role;

/**
 * 全局常量
 * 
 * @author wkipy
 *
 */
public class Consts {

	/**
	 * 会话信息key常量
	 * 
	 * @author wkipy
	 *
	 */
	public static class SessionKeys {
		/**
		 * 用户
		 */
		public static final String SESSION_USER_KEY = "DGJ_USER";
		/**
		 * 菜单
		 */
		public static final String SESSION_MENU_KEY = "DGJ_MENU";
	}

	/**
	 * 系统级常量值
	 * 
	 * @author wkipy
	 *
	 */
	public static class SystemValues {
		public static final int PAGESIZE = 15;
		public static final String IMGURL = "http://7xl7yg.com2.z0.glb.qiniucdn.com/";
		public static final String FILE_PATH = System.getProperty("java.io.tmpdir") + File.separator + "upload";
	}

	/**
	 * 内置角色
	 * 
	 * @author wkipy
	 *
	 */
	public static enum InstalledRoles {
		/**
		 * 平台管理员
		 */
		ADMIN(1, "admin", "最高权限管理员"),
		/**
		 * 资料采集人员
		 */
		DATA_COLLECTION(2, "data-collection", "资料采集"),
		/**
		 * 资料使用者(总公司财务)
		 */
		DATA_USER(2, "data_user", "资料使用者");

		private int id;
		private String name;
		private String desc;

		public Role toRole() {
			Role role = new Role();
			role.setId(id);
			role.setDescription(desc);
			role.setName(name);
			role.setInstalled(true);
			return role;
		}

		/**
		 * @return the id
		 */
		public int getId() {
			return id;
		}

		/**
		 * @param id
		 *            the id to set
		 */
		public void setId(int id) {
			this.id = id;
		}

		/**
		 * @return the name
		 */
		public String getName() {
			return name;
		}

		/**
		 * @param name
		 *            the name to set
		 */
		public void setName(String name) {
			this.name = name;
		}

		/**
		 * @return the desc
		 */
		public String getDesc() {
			return desc;
		}

		/**
		 * @param desc
		 *            the desc to set
		 */
		public void setDesc(String desc) {
			this.desc = desc;
		}

		/**
		 * @param id
		 * @param name
		 */
		private InstalledRoles(int id, String name, String desc) {
			this.id = id;
			this.name = name;
			this.desc = desc;
		}

	}

	/**
	 * 权限分组,菜单分组
	 * 
	 * @author wkipy
	 *
	 */
	public static enum PermissionGroup {
		/**
		 * 组织架构
		 */
		STRUTS_ADMIN("组织架构", "menu-icon fa fa-list", 2, "struts"),
		/**
		 * 图像采集
		 */
		IMAGE_ADMIN("图像采集", "menu-icon fa fa-camera-retro", 3, "image"),
		/**
		 * 用户管理
		 */
		USER_ADMIN("用户管理", "menu-icon glyphicon glyphicon-user", 1, "user");
		/*
		 * 名称
		 */
		private String name;
		/**
		 * Icon
		 */
		private String icon;
		/**
		 * 顺序
		 */
		private int index;

		private String nameSpace;

		private PermissionGroup(String name, String icon, int index, String nameSpace) {
			this.name = name;
			this.icon = icon;
			this.index = index;
			this.nameSpace = nameSpace;
		}

		public String getNameSpace() {
			return nameSpace;
		}

		public void setNameSpace(String nameSpace) {
			this.nameSpace = nameSpace;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getIcon() {
			return icon;
		}

		public void setIcon(String icon) {
			this.icon = icon;
		}

		public int getIndex() {
			return index;
		}

		public void setIndex(int index) {
			this.index = index;
		}

	}

	/**
	 * 内置权限
	 * 
	 * @author wkipy
	 *
	 */
	public static enum InstalledPermission {
		/**
		 * 分支机构列表
		 */
		SUBSIDIARY_LIST(6, "subsidiary_list", "分支机构", true, 0, PermissionGroup.STRUTS_ADMIN, "/subsidiary/list", "subsidiary_list"),
		/**
		 * 项目部列表
		 */
		PROJECT_LIST(7, "project_list", "项目列表", true, 0, PermissionGroup.STRUTS_ADMIN, "/project/list", "project_list"),
		/**
		 * 合同列表
		 */
		CONTRACT_LIST(8, "contract_list", "合同列表", true, 0, PermissionGroup.STRUTS_ADMIN, "/contract/list", "contract_list"),
		/**
		 * 资料采集
		 */
		IMAGE_GATHER(5, "image_gather", "图像采集", true, 0, PermissionGroup.IMAGE_ADMIN, "/image/gather", "image_gather"),
		/**
		 * 资料列表
		 */
		IMAGE_LIST(4, "image_list", "资料列表", true, 0, PermissionGroup.IMAGE_ADMIN, "/image/list", "image_list"),
		/**
		 * 用户列表
		 */
		USER_LIST(1, "user_list", "用户列表", true, 0, PermissionGroup.USER_ADMIN, "/user/list", "user_list"),
		/**
		 * 角色列表
		 */
		ROLE_LIST(2, "role_list", "角色列表", true, 0, PermissionGroup.USER_ADMIN, "/role/list", "role_list"),
		/**
		 * 权限列表
		 */
		PERMISSION_LIST(3, "permission_list", "权限列表", true, 0, PermissionGroup.USER_ADMIN, "/permission/list", "permission_list");

		private int id;
		private String name;
		private String desc;
		private boolean menu;
		private int need;
		private PermissionGroup menuGroup;
		private String url;
		private String key;

		private InstalledPermission(int id, String name, String desc, boolean menu, int need, PermissionGroup menuGroup, String url, String key) {
			this.id = id;
			this.name = name;
			this.desc = desc;
			this.menu = menu;
			this.need = need;
			this.menuGroup = menuGroup;
			this.url = url;
			this.key = key;
		}

		public int getId() {
			return id;
		}

		public void setId(int id) {
			this.id = id;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getDesc() {
			return desc;
		}

		public void setDesc(String desc) {
			this.desc = desc;
		}

		public boolean isMenu() {
			return menu;
		}

		public void setMenu(boolean menu) {
			this.menu = menu;
		}

		public int getNeed() {
			return need;
		}

		public void setNeed(int need) {
			this.need = need;
		}

		public PermissionGroup getMenuGroup() {
			return menuGroup;
		}

		public void setMenuGroup(PermissionGroup menuGroup) {
			this.menuGroup = menuGroup;
		}

		public String getUrl() {
			return url;
		}

		public void setUrl(String url) {
			this.url = url;
		}

		public String getKey() {
			return key;
		}

		public void setKey(String key) {
			this.key = key;
		}

		public Permission toPermission() {
			Permission permission = new Permission();
			permission.setDescription(desc);
			permission.setInstalled(true);
			permission.setName(name);
			permission.setMenuGroup(menuGroup);
			permission.setNeedPermission(need);
			permission.setMenu(menu);
			permission.setUrl(url);
			permission.setHilightKey(key);
			return permission;
		}
	}

}
